package 多线程.抢票;

public class piao implements Runnable {
    static int num = 100;
    Object o = new Object();

    @Override
    public void run() {


                while (true) {
                    synchronized (o) {
                        if(num>0) {
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }

                            System.out.println(Thread.currentThread().getName() + "正在卖" + num + "号票");
                            num--;
                        }
                        if(num==0){
                            break;
                        }
            }
        }

    }
}
